// pages/wm/index.js
const app = getApp()
import http from '../../utils/request.js';
import alert from '../../utils/alert.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    distance_fee:0,
    distance:0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  chooseLocation:function(){
    var that =this;
    wx.chooseLocation({
      success: function (res) {
        http.post(
          app.config.service.getDistance, 
        { lng: res.longitude, lat: res.latitude }
        ).then(data => {
          that.setData({
            map_address: res.address + res.name,
            gcj02_map: res.longitude + ',' + res.latitude,
            distance: data.distance,
            distance_fee:data.distance_fee
          })
        }, err => {
          console.log(err)
        });



      },
      fail: function (res) { },
      complete: function (res) { },
    })
  },
  formSubmit:function(e){
    console.log(e)
    var params = Object.assign({ map_address: this.data.map_address + e.detail.value.user_address, gcj02_map: this.data.gcj02_map }, e.detail.value)

    console.log(params);
    http.post(
      app.config.service.submitWmInfo,
      params
    ).then(data => {
      wx.redirectTo({
        url: '../goods/index?order_no='+data.order_no,
      })
    }, err => {
      console.log(err)
    });

  }
})